package net.cc.jsy.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.io.IOException;

/**
 *
 *
 * @author jingshiyu
 *
 * @date 2021.11.16 15:05:12
 *
 * @desc
 */
@Component
public class StartRunConfig  implements ServletContextAware {
    @Value("${server.port:8071}")
    private String port;
    /**
     * 在填充普通bean属性之后但在初始化之前调用
     * 类似于initializingbean的afterpropertiesset或自定义init方法的回调
     *
     */
    @Override
    public void setServletContext(ServletContext servletContext) {
        String url ="http://localhost:"+port+"/index.html";
        try {
            Runtime.getRuntime().exec("cmd /c start " + url);//启用cmd运行默认浏览
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
